//
//  VertexBuffer.cpp
//  LearnOpenGL
//
//  Created by Mr.Optimist on 2022/2/9.
//

#include "VertexBuffer.hpp"
#include "Renderer.hpp"

VertexBuffer::VertexBuffer(const void *data, unsigned int size) {
    GLCall(glGenBuffers(1, &m_RendererID));                            // 生成buffer
    GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID));               // 绑定buffer到指针
    GLCall(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW)); // 绑定buffer顶点数据
}

VertexBuffer::~VertexBuffer() {
    GLCall(glDeleteBuffers(1, &m_RendererID));
}

void VertexBuffer::Bind() const {
    GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID));
}

void VertexBuffer::UnBind() const {
    GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0));
}
